from datetime import datetime, date
from  typing import Dict
import time

import json

date_formate_str = r"%Y-%m-%d"
time_formate_str = r"%Y-%m-%d %H:%M:%S"

# region 日期时间的相关操作
def get_date_str(datatime1: date):
    """将日期转格式转为字符串"""
    return datatime1.strftime(date_formate_str)

def get_time_str(datatime1: date):
    """将日期转格式转为字符串"""
    return datatime1.strftime(time_formate_str)


def get_today_str():
    """获取今天的日期字符串"""
    current_date = date.today()
    return get_date_str(current_date)

def get_now_str():
    """获取当前时间的字符串"""
    current_date = datetime.now
    return get_time_str(current_date)


def get_day_differ(old_day: datetime, new_day: datetime):
    """获取日期差"""
    delta = new_day - old_day
    return delta.days


def date_str_to_date_time(date_str):
    """将日期字符字符串转为日期"""
    return datetime.strptime(date_str, date_formate_str)

def time_str_to_date_time(time_str):
    """将时间字符串转为时间"""
    return datetime.strptime(time_str, time_formate_str)


def datetime_str_to_datetime(data_time_str):
    if len(data_time_str)>12:
        return time_str_to_date_time(data_time_str)
    else:
        return date_str_to_date_time(data_time_str)


# endregion

# region 文件相关操作

def save_json(dict_data:Dict,file_path:str):
    with open(file_path,"w",encoding='utf-8') as file:
        json_data = json.dumps(dict_data)
        file.write(json_data)


# endregion

def timeit(func):
    def wrapper(*args, **kwargs):
        start_time = time.time()
        result = func(*args, **kwargs)
        end_time = time.time()
        execution_time = end_time - start_time
        print(f"Execution time: {execution_time} seconds")
        return result
    return wrapper